package com.isoft.systemprovidor.service.perinfor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.isoft.systemprovidor.bean.ResponseData;
import com.isoft.systemprovidor.bean.ResultCode;
import com.isoft.systemprovidor.dao.perinfor.Perinfor_Relative_Criminal_Dao;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Relative_Criminal;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Relative_Familynember;
import com.isoft.systemprovidor.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Perinfor_Relative_Criminal_Service {
    @Autowired
    Perinfor_Relative_Criminal_Dao criminal_dao;
    /*验证身份证号*/
    public ResponseData idcardIsExist(String idcard){
        ResponseData responseData =new ResponseData();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("idcard", idcard);
        //判断身份证是否在数据库已存在，若存在返回前端消息为身份证已存在
        if (criminal_dao.selectOne(wrapper)!= null){
            responseData.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            responseData.setMsg("身份证已存在");
            return responseData;
        }
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        return responseData;
    }
    /*查看家庭主要成员的形式责任信息*/
    public ResponseData selectCriminal(String sysuserid){
        ResponseData responseData =new ResponseData();
        if (sysuserid.isEmpty()|| null == sysuserid){
            responseData.setErrorCode(ResultCode.PARAM_IS_BLANK.getCode());
            responseData.setMsg(ResultCode.PARAM_IS_BLANK.getMessage());
            return responseData;
        }
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("sysuserid",sysuserid);
        wrapper.eq("islock",0);
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(criminal_dao.selectList(wrapper));
        return responseData;
    }
    /*修改家庭主要成员的形式责任信息*/
    public boolean changeCriminal(Perinfor_Relative_Criminal criminal){
        if((null == criminal)||(!IdUtil.idCheck(criminal.getId()))||(criminal.getSysuserid().isEmpty())){
            return false;
        }
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sysuserid",criminal.getSysuserid());
        wrapper.eq("id",criminal.getId());
        return criminal_dao.update(criminal,wrapper)>0;

    }
    /*添加家庭主要成员的形式责任信息*/
    public boolean insertCriminal(Perinfor_Relative_Criminal criminal){
        if((null == criminal)||(criminal.getSysuserid().isEmpty())){
            return false;
        }
        return criminal_dao.insert(criminal)>0;
    }
    /*删除家庭主要成员的形式责任信息（逻辑删除）*/
    public boolean islockCriminal(Integer id ,String sysuserid){
        if (id==null|| sysuserid.isEmpty()){
            return false;
        }
        Perinfor_Relative_Criminal criminal = new Perinfor_Relative_Criminal();
        criminal.setIslock(1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        wrapper.eq("sysuserid",sysuserid);
        return criminal_dao.update(criminal,wrapper)>0;
    }

}
